package com.lovo.texst1;

import java.text.DecimalFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.format.DecimalStyle;

public class Date {
    public static void main(String[] args) {
        Date date = new Date();
        System.out.println(date.format("2022-07-07"));
        System.out.println(date.function("myName"));
        System.out.println(date.functions("my_name"));
        System.out.println(date.functions1(123444345.00));


    }

    //实现日期格式化处理
    public String format(String dateStr) {
        LocalDate localDate = LocalDate.parse(dateStr);
        LocalDate date = LocalDate.now();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy年M月d日");
        String text = date.format(formatter);
        return text;

    }

    //将驼峰命名法(Camel Case)的单词转换为蛇形命名法(Snake Case)的单词。
    public String function(String name) {
        String newName = "";
        for (int i = 0; i < name.length(); i++) {
            char c = name.charAt(i);
            if (Character.isUpperCase(c) && i > 0) {
                newName += "_" + c;
            } else {
                newName += c;
            }
        }
        return newName.toLowerCase();
    }

    //将蛇形命名法的单词转换为驼峰命名法的单词。
    public String functions(String name) {
        String[] names = name.split("_");
        String newName = "";
        for (int i = 0; i < names.length; i++) {
            newName += Character.toUpperCase(names[i].charAt(0)) + names[i].substring(1);
        }
        return newName;
    }


    //编写一个函数，将货币数字以千分位的方式表示。
    public String functions1(double d) {
        DecimalFormat decimalFormat=new DecimalFormat(",###.00");
        return decimalFormat.format(d);
    }
}
